﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;

using XRpgLibrary.ScriptClasses;
using XRpgLibrary.CharacterClasses;
using XRpgLibrary.TileEngine;

namespace XRpgLibrary.Scripts.Movement
{
    public class Avoid : GameScript
    {
        private float outerRadius;
        private float innerRadius;
        private bool avoiding = false;

        public Avoid(float outerRadius = 320f, float innerRadius = 128f)
        {
            this.outerRadius = outerRadius;
            this.innerRadius = innerRadius;
        }
            
        public override void Execute(Character self, object trigger, ScriptContext context, GameTime gameTime)
        {
            Vector2 deltaVector = context.Player.Sprite.Position - self.Sprite.Position;

            if (avoiding && deltaVector.Length() < outerRadius)
            {
                self.Move(-1 * deltaVector, (float)gameTime.ElapsedGameTime.TotalSeconds);
            }
            else if (!avoiding && deltaVector.Length() < innerRadius)
            {
                avoiding = true;
            }
            else if (avoiding)
            {
                avoiding = false;
            }
            else
                self.Move(Vector2.Zero);
        }
    }
}
